package com.bianguo.android.baidumapdemo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bianguo.android.baidumapdemo.R;
import com.bianguo.android.baidumapdemo.entity.GoodsData;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/3/5.
 */

public class GoodsAdapter extends BaseRecyclerAdapter<GoodsData> {

    public GoodsAdapter(Context mContext, ArrayList<GoodsData> list) {
        super(mContext, list);
    }

    @Override
    public BaseViewHolder createHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case ITEM_TYPE_HEAD:
                view = inflater.inflate(R.layout.item_goods_title_layout, parent, false);
                return new HeadViewHolder(view);
            case ITEM_TYPE_NORMAL:
                view = inflater.inflate(R.layout.item_goods_layout, parent, false);
                return new ViewHolder(view);
        }
        return null;
    }

    @Override
    public void bindHolder(BaseViewHolder holder, int position) {
        switch (getItemViewType(position)) {
            case ITEM_TYPE_HEAD:
                HeadViewHolder headHolder = (HeadViewHolder) holder;
                headHolder.titleTv.setText(list.get(position).getGoodsName());
                break;
            case ITEM_TYPE_NORMAL:
                ViewHolder viewHolder = (ViewHolder) holder;
                viewHolder.nameTv.setText(list.get(position).getGoodsName());
                break;
        }
    }

    @Override
    public int getItemViewType(int position) {
        return list.get(position).isTitle() ? ITEM_TYPE_HEAD : ITEM_TYPE_NORMAL;
    }

    public static class HeadViewHolder extends BaseViewHolder {

        @BindView(R.id.item_goods_title)
        TextView titleTv;

        public HeadViewHolder(View itemView) {
            super(itemView);
        }
    }

    public static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.item_goods_name)
        TextView nameTv;

        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
